package com.ruoyi.APPMS.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.APPMS.domain.Vehicle;
import com.ruoyi.APPMS.service.IVehicleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆管理Controller
 *
 * @author 吴春梅
 * @date 2023-07-02
 */
@Api(tags="车辆管理控制器类")
@RestController
@RequestMapping("/vehicle/vehicle")
public class VehicleController extends BaseController
{
    @Autowired
    private IVehicleService vehicleService;

    /**
     * 查询车辆管理列表
     */
    @ApiOperation("查询车辆管理列表")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:list')")
    @GetMapping("/list")
    public TableDataInfo list(Vehicle vehicle)
    {
        startPage();
        List<Vehicle> list = vehicleService.list(vehicle);
        return getDataTable(list);
    }

    /**
     * 导出车辆管理列表
     */
    @ApiOperation("导出车辆管理列表")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:export')")
    @Log(title = "车辆管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Vehicle vehicle)
    {
        List<Vehicle> list = vehicleService.list(vehicle);
        ExcelUtil<Vehicle> util = new ExcelUtil<Vehicle>(Vehicle.class);
        util.exportExcel(response, list, "车辆管理数据");
    }

    /**
     * 获取车辆管理详细信息
     */
    @ApiOperation("获取车辆管理详细信息")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:query')")
    @GetMapping(value = "/{vehicleid}")
    public AjaxResult getInfo(@PathVariable("vehicleid") Long vehicleid)
    {
        return success(vehicleService.getById(vehicleid));
    }

    /**
     * 新增车辆管理
     */
    @ApiOperation("新增车辆管理")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:add')")
    @Log(title = "车辆管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Vehicle vehicle)
    {
        vehicle.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

        return toAjax(vehicleService.save(vehicle));
    }

    /**
     * 修改车辆管理
     */
    @ApiOperation("修改车辆管理")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:edit')")
    @Log(title = "车辆管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Vehicle vehicle)
    {
        vehicle.setModifytime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

        return toAjax(vehicleService.updateById(vehicle));
    }

    /**
     * 删除车辆管理
     */
    @ApiOperation("删除车辆管理")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:remove')")
    @Log(title = "车辆管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{vehicleids}")
    public AjaxResult remove(@PathVariable List<Long> vehicleids)
    {
        return toAjax(vehicleService.removeByIds(vehicleids));
    }

    @ApiOperation("查询车辆品牌信息，初始化下拉列表")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:getBrands')")
    @GetMapping(value = "getBrands")
    public AjaxResult getBrands()
    {
        return AjaxResult.success(vehicleService.list());
    }

}
